#include <iostream>
#include <vector>

using namespace std;

class Solution {
private:
    struct link_map {
        vector<int> link;
        int dfn = -2;
        int low = -2;
        bool visited = false;
    };
    vector<link_map> link_map;
    vector<vector<int>> output;
    int dfs_tarjan(int index, int num, int prv_index) {
        link_map[index].dfn = num;
        link_map[index].low = num;
        for (int i = 0; i < link_map[index].link.size(); i++) {
            if (link_map[index].link[i] == prv_index) {
                continue;
            } else if (link_map[link_map[index].link[i]].dfn == -2) {
                num++;
                link_map[index].low = min(link_map[index].low, dfs_tarjan(link_map[index].link[i], num, index));
            } else {
                link_map[index].low = min(link_map[index].low, link_map[link_map[index].link[i]].dfn);
            }
        }
        return link_map[index].low;
    }
    void dfs(int index) {
        link_map[index].visited = true;
        for (int i = 0; i < link_map[index].link.size(); i++) {
            if (link_map[link_map[index].link[i]].visited) {
                continue;
            }
            if (link_map[link_map[index].link[i]].low > link_map[index].dfn) {
                output.push_back({index, link_map[index].link[i]});
            }
            dfs(link_map[index].link[i]);
        }
    }
public:
    vector<vector<int>> criticalConnections(int n, vector<vector<int>>& connections) {
        link_map.resize(n);
        for (vector<int> connect: connections) {
            link_map[connect[0]].link.push_back(connect[1]);
            link_map[connect[1]].link.push_back(connect[0]);
        }
        dfs_tarjan(0, 0, -1);
        dfs(0);
        return output;
    }
};


int main() {
    Solution solution;
    vector<vector<int>> connections = {{0, 1}, {1, 2}, {2, 0}, {1, 3}};
    vector<vector<int>> out = solution.criticalConnections(4, connections);
    for (vector<int> connect: out) {
        cout << connect[0] << "," << connect[1] << endl;
    }
}